@extends('admin.default')
@section('title', '添加管理员')
@section('content')
    <div class="layui-fluid">
        <div class="layui-row">
            <form class="layui-form">
                <div class="layui-form-item">
                    <label for="L_email" class="layui-form-label">
                        <span class="x-red">*</span>所属科目</label>
                    <div class="layui-form-mid layui-word-aux">
                        <span class="layui-badge layui-badge-green">{{$id->name}}</span>
                    </div>
                </div>
                <div class="layui-form-item">
                    <label for="name" class="layui-form-label">
                        <span class="x-red">*</span>章节名称
                    </label>
                    <div class="layui-input-inline">
                        <input type="text" id="name" name="name" class="layui-input">
                    </div>
                    <div class="layui-form-mid layui-word-aux">
                        <span class="x-red">*</span>章节名最小4个字符
                    </div>
                </div>
                <div class="layui-form-item">
                    <label for="order" class="layui-form-label">
                        <span class="x-red">*</span>权重
                    </label>
                    <div class="layui-input-inline">
                        <input type="text" id="order" name="order" autocomplete="off" value="56" class="layui-input">
                    </div>
                    <div class="layui-form-mid layui-word-aux">
                        <span class="x-red">*</span>权重越小，排序越在前面
                    </div>
                </div>
                <input type="hidden" name="	subject" value="{{$id->id}}">
                {{csrf_field()}}
                <div class="layui-form-item">
                    <label for="L_repass" class="layui-form-label">
                    </label>
                    <button  class="layui-btn" lay-filter="add" lay-submit="">
                        增加
                    </button>
                </div>
            </form>
        </div>
    </div>
    <script>layui.use(['form', 'layer'],
            function() {
                $ = layui.jquery;
                var form = layui.form,
                    layer = layui.layer;

                form.on('submit(add)',
                    function(data) {
                        console.log(data);
                        //发异步，把数据提交给php
                        data = data.field;
                        $.ajax({
                            type: 'POST',
                            url: '{{route('admin.sections.store')}}',
                            data: data,
                            dataType: 'json',
                            success: function (data){
                                if(data == 1){
                                    layer.alert('修改成功', {
                                        icon: 1,
                                        skin: 'layui-layer-molv' //样式类名
                                        ,closeBtn: 0
                                    }, function(){
                                        var index = parent.layer.getFrameIndex(window.name);
                                        parent.layer.close(index);
                                        parent.location.reload();
                                    });
                                } else{
                                    layer.alert('修改失敗', {
                                        icon: 2,
                                        skin: 'layui-layer-molv' //样式类名
                                        ,closeBtn: 0
                                    });
                                }
                            },
                            error: function(res){
                                var msg=JSON.parse(res.responseText);
                                layer.alert(msg.message, {
                                    icon: 2,
                                    title: '提示信息',
                                    skin: 'layui-layer-molv' //样式类名
                                    ,closeBtn: 0
                                });
                            }
                        });
                        return false;
                    });

            });</script>
@stop
